/*
 * Copyright (c) 2018 22420103@QQ.COM 版权所有
 */
package com.lehe.controller.admin;

import com.lehe.entry.BaseResponse;
import com.lehe.entry.SqlParameterDto;
import com.lehe.entry.WhiteUserDto;
import com.lehe.entry.page.PageDto;
import com.lehe.service.impl.WhiteUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 类的功能描述
 *
 * @author 王丹
 * @since 2018-02-04
 */
@RequestMapping("admin/whiteUser")
@Controller
public class WhiteUserController extends BaseAdminController{

    @Autowired
    WhiteUserService whiteUserService;

    @RequestMapping("")
    public String index(Model model){
        return "admin/whiteUser/index";
    }

    @RequestMapping("list")
    public String userManagerList(SqlParameterDto sqlParameterDto, Model model){
        PageDto pd = new PageDto(sqlParameterDto.getPage(), sqlParameterDto.getPageSize());
        sqlParameterDto.setPage(pd.getPageIndex());
        sqlParameterDto.setPageSize(pd.getPageSize());
        Long count = whiteUserService.queryCountBymult(sqlParameterDto);
        List<WhiteUserDto> list = whiteUserService.queryBymult(sqlParameterDto);
        model.addAttribute("data",list);
        pd.setRecordCount(count.intValue());
        model.addAttribute("page",pd);
        model.addAttribute("parameterDto",sqlParameterDto);
        return "admin/whiteUser/list";
    }

    @RequestMapping("add")
    public String add(SqlParameterDto sqlParameterDto, Model model){
        return "admin/whiteUser/add";
    }

    @RequestMapping("insert")
    @ResponseBody
    public BaseResponse insert(WhiteUserDto whiteUserDto){
        return whiteUserService.insert(whiteUserDto);
    }

    @RequestMapping("delete")
    @ResponseBody
    public BaseResponse delete(Long id){
        return whiteUserService.deleteById(id);
    }

}
